#ifndef SYS_TIMER_H
#define	SYS_TIMER_H

#include "mytype.h"
#include "stdint.h"

#ifdef   _TIMER_MODULE_
#define  TIM_EXT
#else
#define  TIM_EXT  extern
#endif      
    
#define SYSTICK_CYCLE             1000UL     //system tick timer interrupt cycle //us
#define COUNTER_10MS              ((uint8_t)((10UL*1000UL/SYSTICK_CYCLE)))         
#define COUNTER_20MS              ((uint8_t)((20UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_30MS              ((uint8_t)((30UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_50MS              ((uint8_t)((50UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_100MS             ((uint8_t)((100UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_200MS             ((uint8_t)((200UL*1000UL/SYSTICK_CYCLE)))

#define COUNTER_125MS             ((uint8_t)((125UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_250MS             ((uint8_t)((250UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_500MS             ((uint16_t)((500UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_1S                ((uint16_t)((1000UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_2S                ((uint16_t)((2000UL*1000UL/SYSTICK_CYCLE)))
#define COUNTER_3S                ((uint16_t)((3000UL*1000UL/SYSTICK_CYCLE)))


TIM_EXT  uint8_t Counter_10ms;
TIM_EXT  uint8_t Counter_20ms;
TIM_EXT  uint8_t Counter_30ms;
TIM_EXT  uint8_t Counter_50ms;
TIM_EXT  uint8_t Counter_100ms;
TIM_EXT  uint8_t Counter_200ms;

TIM_EXT  uint8_t Counter_125ms;
TIM_EXT  uint8_t Counter_250ms;
TIM_EXT  uint16_t Counter_500ms;
TIM_EXT  uint16_t Counter_1s;
TIM_EXT  uint16_t Counter_2s;
TIM_EXT  uint16_t Counter_3s;

TIM_EXT  uint8_t AutoTickCnt;
TIM_EXT  uint8_t SysTickCnt;
TIM_EXT  uint8_t AutoTimerCnt;
TIM_EXT  uint8_t  PowerUpTimeCnt;

TIM_EXT  UINT8_BITS PulseSt1;
TIM_EXT  UINT8_BITS PulseSt2;
TIM_EXT  UINT8_BITS WaveSt;

#define bPulse_10ms      PulseSt1.bits.b0
#define bPulse_20ms      PulseSt1.bits.b1
#define bPulse_30ms      PulseSt1.bits.b2
#define bPulse_50ms      PulseSt1.bits.b3
#define bPulse_100ms     PulseSt1.bits.b4
#define bPulse_200ms     PulseSt1.bits.b5
#define bPulse_Tick      PulseSt1.bits.b7

#define bPulse_125ms     PulseSt2.bits.b0
#define bPulse_250ms     PulseSt2.bits.b1
#define bPulse_500ms     PulseSt2.bits.b2
#define bPulse_1s        PulseSt2.bits.b3
#define bPulse_2s        PulseSt2.bits.b4
#define bPulse_3s        PulseSt2.bits.b5


#define bWave_125ms      WaveSt.bits.b0
#define bWave_250ms      WaveSt.bits.b1
#define bWave_500ms      WaveSt.bits.b2
#define bWave_1s         WaveSt.bits.b3
#define bWave_2s         WaveSt.bits.b4
#define bWave_3s         WaveSt.bits.b5


void SysPulseCreat(void);
void SysPulseClear(void);
void TickIntHook(void);
void SysTickInit(void);

#undef TIM_EXT

#endif	/* SYS_TIMER_H */

